/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;

/**
 *
 * @author sio
 */
public class DAO {
    public static Collection <Dep> getLesDeps(){
         Collection <Dep> colD = new TreeSet <Dep> ();
         
        try{
          Connection con = Connect.get();
            Statement req;
            req = con.createStatement(); 
             ResultSet rs = req.executeQuery( "Select distinct departement from medecin");
               Statement req1;
            req1 = con.createStatement(); 
             
             
             while(rs.next()){
                 
                 
                 Dep d = new Dep(rs.getString("departement"));
                 colD.add(d);
                
             }
        
        }catch(Exception e){
            
        }
        return colD;
    }
    public static Collection <Med> getlesMed(){
        Collection <Med> colM = new TreeSet <Med> ();
        try{
             Connection con = Connect.get();
            Statement req;
            req = con.createStatement(); 
            ResultSet rs = req.executeQuery("select * from medecin");
           while(rs.next()){
                colM.add(new Med(rs.getString("nom"),rs.getString("prenom"),rs.getString("adresse"),
                      rs.getString("tel"),rs.getString("specialitecomplementaire"),rs.getString("id"),rs.getString("departement")));
           }
        }catch(Exception e){
            System.out.println("erreurSQL" + e);
        }
        return colM;
    }
    public static Collection <Specialite> getlesSpe(){
        Collection <Specialite> colS = new TreeSet <Specialite> ();
        try{
             Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            
             ResultSet rs = req.executeQuery( "Select distinct specialitecomplementaire from medecin");
               while(rs.next()){
                 if(rs.getString("specialitecomplementaire")!=null){
                 colS.add(new Specialite (rs.getString("specialitecomplementaire")));
                   }
               }
               
           
        }catch(Exception e){
            
        }
        return colS;
    }
}
